home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-12-24 | 2.7 KB | 140 lines | [TEXT/PJMM] |
- unit Eval;
-
-
- interface
-
-
- uses
-
- Globals, LexicalAnalysis, Parser, SetValues, EvaluateNodes;
-
-
- function eval (var line: str255): str255;
-
-
-
- implementation
-
-
- function eval;
-
-
- label
- 998, 999;
-
- var
- removeblanks: boolean;
- i, j, k, nstart, ntot: longint;
- mrows, ncols: longint;
- save: array2;
- nodetable: hdlarrayhdlnoderecord;
- flag: hdlflagtype;
- store: boolean;
- sy, tokentype: hdlstringarray0;
- pr: hdlintarray0;
- t: hdlextendarray;
-
- begin
-
- sy := hdlstringarray0(NewHandle(SizeOf(stringarray0)));
- tokentype := hdlstringarray0(NewHandle(SizeOf(stringarray0)));
- pr := hdlintarray0(NewHandle(SizeOf(intarray0)));
- t := hdlextendarray(NewHandle(SizeOf(extendarray)));
-
- error := '';
-
- removeblanks := true;
- lexicalanalysis(line, removeblanks, ntot, sy, tokentype, pr, error);
-
- if (error <> '') and (length(error) > 1) then
- begin
- line := 'error';
- eval := error;
- goto 999;
- end;
-
- nstart := 1;
- store := false;
-
- nodetable := hdlarrayhdlnoderecord(NewHandle(SizeOf(arrayhdlnoderecord)));
- flag := hdlflagtype(NewHandle(SizeOf(flagtype)));
-
- if (sy^^[2]^^ = equals) then
- nstart := 3;
-
- for i := nstart to ntot do
- flag^^[i] := false;
-
- for i := nstart to ntot do
- begin
- for k := 1 to numvariables do
- begin
- j := numvariables + 1 - k;
- if (sy^^[i]^^ = strvar^^[j]^^) and ((tokentype^^[i]^^ = 'variable')) then
- begin
- flag^^[i] := true;
- tokentype^^[i]^^ := 'matrix';
- goto 998;
- end;
- end;
- 998:
- end;
-
- save[1] := sy^^[1]^^;
- save[2] := sy^^[2]^^;
-
- for i := nstart to ntot do
- if ((tokentype^^[i]^^ = 'variable') or (tokentype^^[i]^^ = 'matrix')) and (flag^^[i] = false) then
- begin
- error := concat(sy^^[i]^^, ' has not been defined');
- line := 'error';
- eval := error;
- goto 999;
- end;
-
- parser(ntot, sy, tokentype, pr, nodetable, numnodes, error);
-
- if (error <> '') and (length(error) > 1) then
- begin
- eval := error;
- line := 'error';
- goto 999;
- end;
-
- setvalues(nodetable, numnodes, numvariables);
-
- evaluatenodes(nodetable, numnodes, mrows, ncols, t, store, save, error);
-
- if (error <> '') and (length(error) > 1) then
- begin
- line := 'error';
- eval := error;
- goto 999;
- end;
-
- if numnodes <= 0 then
- begin
- line := '';
- eval := '';
- goto 999;
- end;
-
- eval := stringof(t^^[numnodes]^^ : decplaceplus10 : decplace);
-
- if (mrows = 1) and (ncols = 1) then
- line := 'real'
- else
- line := 'matrix';
-
- DisposHandle(handle(nodetable));
- DisposHandle(handle(flag));
- DisposHandle(handle(sy));
- DisposHandle(handle(tokentype));
- DisposHandle(handle(pr));
- DisposHandle(handle(t));
-
-
- 999:
- end;
-
- end.